package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.dto.EmployeeLoginDTO;
import com.itheima.dto.EmployeePageQueryDTO;
import com.itheima.dto.PasswordEditDTO;
import com.itheima.pojo.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmployeeMapper {


    Employee getByUsername(EmployeeLoginDTO employeeLoginDTO);

    /**
     * 修改密码
     * @param passwordEditDTO
     */
    @Update("update employee set password=#{newPassword} where id=#{empId}")
    void updatePassword(PasswordEditDTO passwordEditDTO);

    /**
     * 根据id查询账户
     * @param empId
     * @return
     */
    @Select("select * from employee where id=#{empId}")
    Employee getById(Long empId);

    Page<Employee> pageSelect(EmployeePageQueryDTO employeePageQueryDTO);

    /**
     * 添加
     * @param employee
     */
    @Insert("insert into employee(name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
            "VALUES(#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    void addEmployee(Employee employee);

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    @Select("select * from employee where id =#{id}")
    Employee findById(Integer id);
    /**
     * 修改员工信息
     * @param employee
     * @return
     */

    void updateEmployee(Employee employee);

    @Select("select * from employee")
    List<Employee> findAll();
}
